package com.gitee.wsl.collections.iterator

class FillMinIterator<E>(
    private val it: Iterator<E>,
    private val minCount: Int,
    private val defaultElement: E
) : Iterator<E> {
    private var count = 0

    public override fun hasNext(): Boolean {
        return count <= minCount || it.hasNext()
    }

    public override fun next(): E {
        if (it.hasNext()) {
            count++
            return it.next()
        }

        if (count < minCount) {
            count++
            return defaultElement
        }
        throw NoSuchElementException("iterator count exceed limit: count=$count,limit=$minCount")
    }
}
